$(function () {
	createCode();
	
	$("#loginForm").submit(formloginSubmit);
});

function createCode(){// debugger;
	code = new Array();
	var codeLength = 4;//验证码的长度
	var checkCode= $("#checkCode").val("");
	var selectChar = new Array(2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');
	for(var i=0;i<codeLength;i++) {
	   var charIndex = Math.floor(Math.random()*55);
	   code +=selectChar[charIndex];
	}
	if(code.length != codeLength){
	   createCode();
	}

	$("#checkCode").val(code);
	$("#chCode").val(code);
}

function formloginSubmit() {
	console.log('submit1');
	var username = $.trim($("#username").val());
	var password = $.trim($("#password").val());
	var yzm = $.trim($("#yzm").val());
	var chCode = $.trim($("#chCode").val());
	
	if (!username) {
		$("#note").text("用户名不能为空！");
		$("#username").focus();
		return false;
	}
	if (!password) {
		$("#note").text("密码不能为空！");
		$("#password").focus();
		return false;
	}
	if (!yzm) {
		$("#note").text("验证码不能为空！");
		$("#yzm").focus();
		return false;
	}
	var y = yzm.toUpperCase();
	var c = chCode.toUpperCase();
	if (y != c) {
		$("#note").text("验证码不正确！");
		createCode();
		$("#yzm").val('');
		$("#yzm").focus();
		return false;
	}
	$("#loginForm")[0].submit();
}
function EnterName() {
    if (event.keyCode == 13) {
        $("button.ore_bg").click();
    }
}